import { configureStore } from "@reduxjs/toolkit"
import { createSlice}  from "@reduxjs/toolkit"
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
const stateRudux=createSlice({
    name:"stateRudux",
    initialState:{
        componentName:"全局组件状态管理",
        count:0,
        list:[],
       
    },
    reducers:{
        addNums(state,actions){
            state.count+=1
        },
        addList(state,actions){
            state.list=actions.payload
        }
    }
})
const stateRuduxPersistConfig = {
    key: 'stateRudux',
    storage,
    // whitelist: ['num'] // 只持久化 num 
};
const stateRuduxPersistConfigs = persistReducer(stateRuduxPersistConfig, stateRudux.reducer);
export const store=configureStore({
    reducer:stateRuduxPersistConfigs,
    middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware({
            serializableCheck: false
        })
})
export const {addNums,addList}=stateRudux.actions
export const persistor = persistStore(store)